<jsp:directive.page session="true" />

<jsp:useBean id="register" class="dasregistry.registryBean" scope="session"/> 
<jsp:directive.page import="org.biojava.dasobert.dasregistry.DasCoordinateSystem"/>
<jsp:directive.page import="org.biojava.dasobert.dasregistry.DasCoordSysComparator"/>
<jsp:directive.page import="org.biojava.services.das.registry.DasRegistrySql" />
<jsp:directive.page import="java.util.Comparator"/>

<%@ page import="org.biojava.services.das.dao.Role" %>
<%@ page import="org.biojava.services.das.dao.RegistryUser" %>
<%@ page import="org.biojava.services.das.registry.UserManager" %>
<%@ page import="org.biojava.dasobert.das.Capabilities"%>
<%@ page import="java.util.List" %>

<%@ include file="logincheck.jsp" %>
<jsp:directive.page import="org.springframework.beans.factory.BeanFactory"/>
<jsp:directive.page import="org.springframework.context.support.ClassPathXmlApplicationContext"/>

<% String title="register DAS 1 source";
   String header=title;
   
   BeanFactory ctx=(new ClassPathXmlApplicationContext("SpringDAO.xml"));
		DasRegistrySql registry=(DasRegistrySql)ctx.getBean("registryBean");
%>


<%@ include file="sangerheader.jsp" %>

<div id="main">

<%
if ( email == null ) {
	%>
	<%@ include file="notLoggedIn.jsp" %>
	<% 
	}
%>

<h2> Step 1/3 register a new DAS 1 source </h2>

<p>

<%@ include file="sangertablestart.jsp" %>

<form method="post" action="registertestcodes.jsp" name="register_form">
<!--  set a bland testcode here as at the moment we cant use one be registration needs it -->
<input type="hidden" name="testCodes" value="">
<!-- title/nickname -->
     <tr class="row1"><td valign="top">
     1.
     </td>
     <td valign="top">
     Title/Nickname
     </td>
     <td>
     <input type="input" name="nickname" size="40" value="<%
     String nickname = register.getNickname();
     out.print(nickname);
     %>"/>
     </td>

     <td valign="top" align="right">	
	 <a href="help_reference.jsp#nickname">help</a><br/>
     </td>

     </tr>


<!-- coordianteSystem -->
	<tr class="row2"><td valign="top">
	2.
	</td>
	<td valign="top">
	Choose Coordinate System     </td>
	<td><select  name="CSTypes" multiple size="5">
	<%
	
	List<DasCoordinateSystem> coords = registry.getAllCoordinateSystems();
	Comparator dsc = DasCoordSysComparator.fromString("name");
	java.util.Collections.sort(coords,dsc);
	
	for ( int i=0; i< coords.size();i++) {
		DasCoordinateSystem coord = coords.get(i);
		%>
		<option value="<%=coord.toString()%>"><%=coord.toString()%></option>
		<%
	}
	register.setCSTypes(new String[0]);
	%>
	</select> 
	</td>

	<td valign="top" align="right">	
	<a href="help_coordsys.jsp">help</a><br/>
	</td>
	</tr>

	

<!-- DAS url -->
	<tr class="row1"><td valign="top">
	3.</td>
	<td> DAS url     </td>
	<td><input type="input" name="dasurl" size="40" value="<%
	
				String dasurl = register.getDasurl();
				if (dasurl == null) { 
					out.print("http://");
				} else {
					out.print(dasurl);
				}

								%>"/> 
	</td>

	<td valign="top" align="right">	
	<a href="help_reference.jsp#url">help</a>
	</td>
	</tr>
	


<!--  owner -->
	<tr class="row2"/>
	<td valig="top">
	4.</td>
	<td>Owner</td>
	<td><%if ( email == null ) {%>
	   not logged in.
	
	<%} else {
		out.print(email);
		%><input type="hidden" name="owner" value="<%=email%>"/><%
	} %></td>
	<td valign="top" align="right">	
	<a href="help_email.jsp">help</a>
	</td>
	</tr>
	
<!-- email -->
	<tr class="row1"><td valign="top">
	5.</td>
	<td> Admin email </td>

	<td> 
		<%if ( email == null ) {%>
	<input class="email" type="input" name="adminemail" size="40" value="<%

				String adminemail = register.getAdminemail();
				if (adminemail!=null) { out.print(adminemail);};


								%>">
	<%} else {
		out.print(user.getEmail());
		%><input type="hidden"  name="adminemail" value="<%=user.getEmail()%>"/><%
		
	}%>
	</td>
	<td valign="top" align="right">	
	<a href="help_reference.jsp#email">help</a>
	</td>

	</tr>
	
<!-- description -->
	<tr class="row2"><td valign="top">
	6.</td>
	<td valign="top"> Description</td>
	<td> <textarea COLS="40" ROWS="4" NAME="description" ><%=register.getDescription()%></textarea></td>
	<% register.setDescription(""); %>
	<td valign="top" align="right">	
	<a href="help_reference.jsp#description">help</a>
	</td>

</tr>

<!-- DAS capabilities -->
	<tr class="row1"><td valign="top">
	7.</td>
	<td valign="top"> DAS capabilities</td> 

	<td>    <SELECT NAME="bigFileCap" size="1"><!-- removed multiple attribute as we can only have one bigfile per data source -->

		<% 
		
		
		  String all_capabilities[] = registry.getAllCapabilities();
		  for (int i=0;i<all_capabilities.length;i++){
			  if(Capabilities.isBigFileFormat(all_capabilities[i])){//only give option if it's a bigfileformat type here, uses set method in registryBean to then set a capabilty array in registryBean
		  out.println("<OPTION VALUE=\""+all_capabilities[i]+"\">"+all_capabilities[i]+"</OPTION>");
		  }	
		  }
		  register.setCapabilities(new String[0]);
		  %>
		
		 </SELECT>
		 


	</td>
	<td valign="top" align="right">	
	<a href="help_capabilities.jsp">help</a>
	</td>
	</tr>



<!-- more details url -->
	<tr class="row2">
	<td valign="top">
	8.</td><td> URL for more detailed description</td>
	<td> 
	<input type="text" name="helperurl" size="40"
	<%
	String helpurl = register.getHelperurl();
	if ( helpurl != null ) {
		%>value="<%=helpurl%>"<%
	}
	register.setHelperurl("");
	%>
	/>
	</td>
	<td valign="top" align="right">
	<a href="help_reference.jsp#helperurl">help</a>
	</td>


<!-- labels (groups) -->
	<tr class="row1">
	<td valign="top">
	9.</td>
	<td valign="top"> choose labels</td>
	<td> 	
	<select name="labels" multiple size="4" >
	<%
	String[] labels = registry.getAllLabels();
	for (int i=0; i< labels.length; i++ ) {
	%>
		<option value="<%=labels[i]%>"><%=labels[i]%></option>
	<%
	} 
	register.setLabels(new String[0]);
	%>
	</select>
	</td>
	<td valign="top" align="right">
	<a href="help_reference.jsp#helperurl">help</a><br/>
	</td></tr>
<tr class="row2"><td valign="top">
	10.</td>
	<td valign="top">Select the DAS specification this source conforms to</td><td><select name="spec">
	<option value="1.6E" selected>1.6E</option></select></td><td></td></tr>

<!-- alert me if server is down ... -->
	<tr class="row1">
	<td valign="top">
	11.</td>
	<td valign="top"> send me an alert email if server is down for > 2 days.</td>
	<td> 	
		<input type="checkbox" name="alertMe" value="1" <%
	
	if (email != null ) {
		if ( user.isAlertMe() ) {
			out.print(" checked");
		}
	}
	
	%>/>
		<% register.setAlertMe("0");%>
	</td>
	<td valign="top" align="right">
	<a href="help_reference.jsp#alert">help</a><br/>
	</td>
	</tr>
<% 
if (isAdmin)  {
%>
	<tr class="row2">
	<td valign="top">
	admin only	
	</td>
	<td valign="top"> do not perform the registry validation for this das source</td>
	<td>
		<input type="checkbox" name="ignoreValidation" value="1" />
		<% register.setIgnoreValidation("0");%>
	</td>
	<td valign="top" align="right">
	&nbsp;
	</td>
	</tr>
<% 
}

	%>

<!-- submit -->
	<tr><td colspan="4" align="right">
	<input type="submit" value="save data and goto next step">
	</td>
	</tr>
	</table>


	<!--<input type="hidden" name="numbcoordinateentries" value="2">-->	



</form>


<%@ include file="sangertableend.jsp" %>


<p>

</div>
<%@ include file="sangerfooter.jsp" %>


